<template>
	<div class="inspection">
		<!-- 项目筛选 -->
		<van-tabs type="card" @click="projectChange" color="#87A2FF" custom-class="tabs">
			<van-tab title="项目1"></van-tab>
			<van-tab title="项目2"></van-tab>
		</van-tabs>

		<div class="table">
			<div class="tr">
				<div class="th">巡检时间</div>
				<div class="th">状态</div>
				<div class="th">详情</div>
			</div>
			<div class="tr">
				<div class="td">25年2月第1周</div>
				<div class="td">
					<van-tag type="success">已确认</van-tag>
				</div>
				<div class="td">
					<text class="inspection-btn" @click="lookInspection">查看</text>
				</div>
			</div>
			<div class="tr">
				<div class="td">25年2月第4周</div>
				<div class="td">
					<van-tag type="warning">待确认</van-tag>
				</div>
				<div class="td">
					<text class="inspection-btn inspection-btn-left" @click="lookInspection">查看</text>
					<text class="inspection-btn inspection-btn-right" @click="confirmInspection">确认</text>
				</div>
			</div>
		</div>
		<!-- 分页 -->
		<div class="inspection-footer" v-if="paginateShow">
			<div class="inspection-footer-btn" @click="previous">
				<van-icon name="arrow-left" /> 上一页
			</div>
			<text class="inspection-footer-num">1 / 6</text>
			<div class="inspection-footer-btn" @click="next">
				下一页
				<van-icon name="arrow" />
			</div>
		</div>
	</div>
	<!-- 巡检确认弹框 -->
	<van-overlay :show="isConfirmShow" custom-style="background-color:rgba(0,0,0,.3)">
		<div class="wrapper modal">
			<div class="wrapper-title">确认提示</div>
			<div class="wrapper-main">
				<span>是否确认该巡检？</span>
			</div>
			<div class="wrapper-footer">
				<button class="btn" @click="handleCheckCancel">取消</button>
				<button class="btn" @click="handleCheckConfirm">确定</button>
			</div>
		</div>
	</van-overlay>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onPullDownRefresh
	} from "@dcloudio/uni-app"
	const isConfirmShow = ref(false)
	const projectChange = (event) => {
		const {
			index
		} = event.detail
		console.log(index, 'index')
	}
	const lookInspection = () => {
		uni.navigateTo({
			url: '/modules/checkInfo/pages/index'
		})
	}
	const confirmInspection = () => {
		isConfirmShow.value = true
		paginateShow.value = false
		uni.hideTabBar()
	}
	const previous = () => {
		console.log('上一页')
	}
	const next = () => {
		console.log('下一页')
	}
	const timerId = ref(null)
	//过渡分页显示
	const paginateShow = ref(true)
	const showTabBar = () => {
		if (timerId.value) {
			clearTimeout(timerId.value)
		}
		timerId.value = setTimeout(() => {
			paginateShow.value = true
			uni.showTabBar()
		}, 500)
	}
	const handleCheckCancel = () => {
		isConfirmShow.value = false
		showTabBar()
	}
	const handleCheckConfirm = () => {
		isConfirmShow.value = false
		showTabBar()
	}
	// 下拉刷新
	onPullDownRefresh(() => {
	setTimeout(() => {
			uni.stopPullDownRefresh();
	},1000)
	})
</script>

<style scoped lang="scss">
	.inspection {
		padding: $uni-space-default-20;
		position: relative;
		height: 100vh;
		box-sizing: border-box;

		.table {
			display: flex;
			flex-direction: column;
			margin-top: $uni-space-default-20;

			.tr {
				display: flex;
				flex-direction: row;
			}

			.tr:last-child {
				border-bottom: 1px solid $uni-border-color;
			}

			.th,
			.td {
				width: 33.33%;
				text-align: center;
				border-top: 1px solid $uni-border-color;
				border-left: 1px solid $uni-border-color;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.td:last-child {
				border-right: 1px solid $uni-border-color;
			}

			.th {
				font-weight: bold;
				font-size: $uni-font-size-26-rpx;
				padding: $uni-space-default-20;
				background-color: #B3CCF4;
			}

			.td {
				padding: $uni-space-default-20;
				font-size: $uni-font-size-26-rpx;
			}

			.inspection-btn {
				color: $uni-bg-color-default;
			}

			.inspection-btn-left {
				margin-right: 10rpx;
			}

			.inspection-btn-right {
				margin-left: 10rpx;
			}

			.tabs .van-tabs__scroll--card {
				margin: 0 !important;
			}

		}

		.inspection-footer {
			width: 100%;
			position: absolute;
			bottom: 20rpx;
			left: 0;
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: $uni-font-size-26-rpx;

			.inspection-footer-btn {
				width: 200rpx;
				height: 80rpx;
				background-color: $uni-bg-color-default;
				line-height: 80rpx;
				color: white;
				border-radius: $uni-border-radius-lg;
				text-align: center;
			}
		}
	}
</style>